package com.lc.afbx.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiInsuranceAccidentDetail;
import com.lc.afbx.util.PrefrenceConfig;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2016/7/1.
 */
public class AccidentInsuranceDetailActivity extends BaseActivity implements View.OnClickListener {

    private SimpleDraweeView insurance_detail_iv;
    private TextView insurance_detail_company_tv;
    private TextView insurance_detail_time_tv;
    private TextView insurance_detail_money_tv;
    private WebView insurance_detail_wv;

    private GetApiInsuranceAccidentDetail.Data data;

    private GetApiInsuranceAccidentDetail getApiInsuranceAccidentDetail = new GetApiInsuranceAccidentDetail(new AsyCallBack<GetApiInsuranceAccidentDetail.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiInsuranceAccidentDetail.Info info) throws Exception {

            data = info.data;
            insurance_detail_iv.setImageURI(Uri.parse(info.data.picurl));
            insurance_detail_company_tv.setText(info.data.title);
            insurance_detail_money_tv.setText(info.data.premium);
            insurance_detail_time_tv.setText("保险期限：" + info.data.deadline + "月");
            insurance_detail_wv.loadUrl(info.data.web1);
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_insurance_detail);

        insurance_detail_iv = ((SimpleDraweeView) findViewById(R.id.insurance_detail_iv));
        insurance_detail_company_tv = ((TextView) findViewById(R.id.insurance_detail_company_tv));
        insurance_detail_time_tv = ((TextView) findViewById(R.id.insurance_detail_time_tv));
        insurance_detail_money_tv = ((TextView) findViewById(R.id.insurance_detail_money_tv));
        insurance_detail_wv = ((WebView) findViewById(R.id.insurance_detail_wv));

        getApiInsuranceAccidentDetail.id = getIntent().getStringExtra(PrefrenceConfig.INTENT_TAG);
        getApiInsuranceAccidentDetail.execute(this);


        findViewById(R.id.insurance_detail_bt).setOnClickListener(this);
        findViewById(R.id.insurance_detail_product_detail_tv).setOnClickListener(this);
        findViewById(R.id.insurance_detail_needkonw_tv).setOnClickListener(this);
        findViewById(R.id.insurance_detail_lipei_needkonw_tv).setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.insurance_detail_product_detail_tv:
                colorclear();
                ((TextView) findViewById(R.id.insurance_detail_product_detail_tv)).setTextColor(getResources().getColor(R.color.xinbao));
                insurance_detail_wv.loadUrl(data.web1);
                return;

            case R.id.insurance_detail_needkonw_tv:
                colorclear();
                ((TextView) findViewById(R.id.insurance_detail_needkonw_tv)).setTextColor(getResources().getColor(R.color.xinbao));
                insurance_detail_wv.loadUrl(data.web2);
                return;

            case R.id.insurance_detail_lipei_needkonw_tv:
                colorclear();
                ((TextView) findViewById(R.id.insurance_detail_lipei_needkonw_tv)).setTextColor(getResources().getColor(R.color.xinbao));
                insurance_detail_wv.loadUrl(data.web3);
                return;

            case R.id.insurance_detail_bt:
                Bundle bundle = getIntent().getExtras();

                Intent intent = new Intent(this, AccidentInsuranceFillInfoActivity.class);

                bundle.putSerializable(PrefrenceConfig.BUNDLE_TAG, data);
                intent.putExtras(bundle);
                startActivity(intent);
                return;
        }


    }

    private void colorclear() {
        ((TextView) findViewById(R.id.insurance_detail_product_detail_tv)).setTextColor(getResources().getColor(R.color.text090909));
        ((TextView) findViewById(R.id.insurance_detail_needkonw_tv)).setTextColor(getResources().getColor(R.color.text090909));
        ((TextView) findViewById(R.id.insurance_detail_lipei_needkonw_tv)).setTextColor(getResources().getColor(R.color.text090909));
    }


}
